from langchain.llms.openai import OpenAI
from langchain.schema.callbacks.streaming_stdout import StreamingStdOutCallbackHandler


def method_one():
    llm = OpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()], temperature=0, max_tokens=512)
    resp = llm("给我写一首关于爱情的歌曲")
    print(resp)


def method_two():
    llm = OpenAI(model="gpt-3.5-turbo-instruct", temperature=0, max_tokens=512)
    for chunk in llm.stream("给我写一首关于勇敢追求的中文歌曲"):
        print(chunk, end="", flush=True)